﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WFA_BANHANG.ThuVien;

namespace WFA_BANHANG.HeThong.DynamicMenu
{
    public partial class frmViewDynamicMenu : DevExpress.XtraEditors.XtraForm
    {
        private CreateDynamicMenuBLO _cdmblo;
        private string _menuID;
        private DataSet _ds;

        //method load data to grid
        public void LoadaDataToGrid()
        {

            ADONET adonet = new ADONET();
            _ds = adonet.BindToDataSet("SELECT * FROM ListMenu");
            gridControl1.DataSource = _ds;
            gridControl1.DataMember = "Table";
        }

        public frmViewDynamicMenu()
        {
            InitializeComponent();
            this._menuID = null;
        }

        private void frmViewDynamicMenu_Load(object sender, EventArgs e)
        {
            LoadaDataToGrid();
        }

        private void gridView1_RowClick(object sender, DevExpress.XtraGrid.Views.Grid.RowClickEventArgs e)
        {
            try
            {
                if (gridView1.GetRowCellValue(e.RowHandle, "MenuID").ToString() != null)
                    _menuID = gridView1.GetRowCellValue(e.RowHandle, "MenuID").ToString();
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void btnXoa_Click(object sender, EventArgs e)
        {
            if (!string.IsNullOrEmpty(_menuID))
            {
                if (MessageBox.Show("Có muốn xóa hàng dữ liệu này không?", "Thông báo", MessageBoxButtons.YesNo, MessageBoxIcon.Question)
                   != System.Windows.Forms.DialogResult.Yes) return;

                _cdmblo = new CreateDynamicMenuBLO(3);
                _cdmblo.Cdmdto.MenuID = _menuID;
                _cdmblo.Call();
                LoadaDataToGrid();
            }
            else MessageBox.Show("Mời chọn 1 dòng dữ liệu mà bạn muốn xóa","Thông báo");
        }

        private void repBtnEdit_Click(object sender, EventArgs e)
        {
            try
            {
                if (gridView1.GetRowCellValue(gridView1.FocusedRowHandle, "MenuID").ToString() != null)
                {
                    this.Hide();
                    frmCreateDynamicMenu fcdm = new frmCreateDynamicMenu();
                    fcdm._status = 1;//edit
                    fcdm._dsFrmCreate = _ds;
                    //get a cell of current a row selected
                    DataRow dr = gridView1.GetDataRow(gridView1.FocusedRowHandle);
                    fcdm._menuID = dr["MenuID"].ToString();
                    fcdm.ShowDialog();

                }
            }
            catch (Exception ex) { MessageBox.Show(ex.Message, "Thông báo"); }
        }

       

    }//the end class
}//the end namespace